using System.Collections.Generic;

namespace OffsetPath
{
    // contiene i vari offset a diverse altezze
    public class ContenitoreLivello : List<PolygonalShape>
    {
        public void a()
        {
            ContenitoreLivello collection = new ContenitoreLivello();
            ContenitoreLivello ah2 = new ContenitoreLivello();
            while (base.Count > 0)
            {
                PolygonalShape polygonalShape = base[base.Count - 1];
                base.RemoveAt(base.Count - 1);
                bool flag = false;
                int num = 0;
                while ((num < base.Count) && !flag)
                {
                    ClassAg classAg = new ClassAg();
                    base[num].MethodB1(polygonalShape, ah2, classAg);
                    if (ah2.Count == 1)
                    {
                        base[num] = ah2[0];
                        flag = true;
                    }
                    else
                    {
                        ah2.Clear();
                        num++;
                    }
                }
                if (!flag)
                {
                    collection.Add(polygonalShape);
                }
            }
            base.AddRange(collection);
        }

        public void a(ClassAg A_0)
        {
            ClassAg.EnumA c = A_0.c;
            switch (A_0.c)
            {
                case ClassAg.EnumA.b:
                    for (int i = 0; i < base.Count; i++)
                    {
                        base[i].e();
                    }
                    A_0.c = ClassAg.EnumA.a;
                    break;

                case ClassAg.EnumA.d:
                    for (int j = 0; j < base.Count; j++)
                    {
                        base[j].MethodA1(A_0);
                    }
                    A_0.c = ClassAg.EnumA.e;
                    break;
            }
            ContenitoreLivello collection = new ContenitoreLivello();
            ContenitoreLivello ah2 = new ContenitoreLivello();
            ContenitoreLivello ah3 = new ContenitoreLivello();
            ContenitoreLivello ah4 = new ContenitoreLivello();
            ContenitoreLivello ah5 = new ContenitoreLivello();
            int num3 = this.b();
            if (num3 == 0)
            {
                num3 = 10;
            }
            ah3.AddRange(this);
            base.Clear();
            do
            {
                num3 *= 3;
                base.AddRange(ah2);
                ah2.Clear();
                while (ah3.Count > 0)
                {
                    PolygonalShape item = ah3[ah3.Count - 1];
                    ah3.RemoveAt(ah3.Count - 1);
                    if (item.g() > num3)
                    {
                        ah5.Add(item);
                    }
                    else
                    {
                        base.Add(item);
                    }
                }
                ah3.AddRange(ah5);
                ah5.Clear();
                while (base.Count > 0)
                {
                    PolygonalShape ai2 = base[base.Count - 1];
                    base.RemoveAt(base.Count - 1);
                    bool flag = false;
                    int index = 0;
                    while ((index < base.Count) && !flag)
                    {
                        base[index].MethodB1(ai2, ah4, A_0);
                        if (ah4.Count == 1)
                        {
                            PolygonalShape ai3 = ah4[ah4.Count - 1];
                            ah4.RemoveAt(ah4.Count - 1);
                            if (ai3.g() > num3)
                            {
                                base.RemoveAt(index);
                                ah3.Add(ai3);
                            }
                            else
                            {
                                base[index] = ai3;
                                index++;
                            }
                            flag = true;
                        }
                        else
                        {
                            if (ah4.Count != 0)
                            {
                                A_0.MethodD();
                            }
                            ah4.Clear();
                            index++;
                        }
                    }
                    if (!flag)
                    {
                        bool flag2 = false;
                        for (int k = 0; k < ah3.Count; k++)
                        {
                            if (ai2.GetExternPolygon().z().e(ah3[k].GetExternPolygon().z()))
                            {
                                flag2 = true;
                                break;
                            }
                        }
                        if (flag2)
                        {
                            ah2.Add(ai2);
                        }
                        else
                        {
                            collection.Add(ai2);
                        }
                    }
                }
            }
            while (ah3.Count != 0);
            base.AddRange(collection);
            collection.Clear();
            A_0.c = c;
        }

        public void a(ContenitoreLivello A_0)
        {
            ContenitoreLivello collection = new ContenitoreLivello();
            while (A_0.Count > 0)
            {
                PolygonalShape polygonalShape = A_0[A_0.Count - 1];
                A_0.RemoveAt(A_0.Count - 1);
                if (!this.b(polygonalShape))
                {
                    collection.Add(polygonalShape);
                }
            }
            base.AddRange(collection);
        }

        public void a(List<PolygonalShape> A_0)
        {
            base.AddRange(A_0);
            A_0.Clear();
        }

        public void a(List<OffsetProfilo2D> A_0)
        {
            if (base.Count != 0)
            {
                while (A_0.Count > 0)
                {
                    OffsetProfilo2D offsetProfilo2D = A_0[A_0.Count - 1];
                    A_0.RemoveAt(A_0.Count - 1);
                    if (offsetProfilo2D.GetListaLineaArco().Count > 0)
                    {
                        int num = base.Count - 1;
                        bool flag = false;
                        while ((num > 0) && !flag)
                        {
                            if (base[num].MethodA1(offsetProfilo2D.GetListaLineaArco()[0].h()))
                            {
                                base[num].MethodA1(offsetProfilo2D);
                                flag = true;
                            }
                            num--;
                        }
                        if (!flag)
                        {
                            base[0].MethodA1(offsetProfilo2D);
                        }
                    }
                }
            }
        }

        public void a(PolygonalShape A_0)
        {
            if (!this.b(A_0))
            {
                base.Add(A_0);
            }
        }

        public int b()
        {
            int num = -1;
            for (int i = 0; i < base.Count; i++)
            {
                int num3 = base[i].g();
                if (num3 < num)
                {
                    num = num3;
                }
            }
            return num;
        }

        public void b(List<OffsetProfilo2D> A_0)
        {
            for (int i = 0; i < A_0.Count; i++)
            {
                PolygonalShape item = new PolygonalShape();
                item.MethodB1(A_0[i]);
                base.Add(item);
            }
            A_0.Clear();
        }

        public bool b(PolygonalShape A_0)
        {
            ContenitoreLivello collection = new ContenitoreLivello();
            ContenitoreLivello ah2 = new ContenitoreLivello();
            ClassAg classAg = new ClassAg();
            while ((base.Count > 0) && (A_0 != null))
            {
                PolygonalShape item = base[base.Count - 1];
                base.RemoveAt(base.Count - 1);
                item.MethodB1(A_0, ah2, classAg);
                if (ah2.Count == 1)
                {
                    A_0 = null;
                    item = null;
                    this.a(ah2[0]);
                    ah2.Clear();
                }
                else
                {
                    ah2.Clear();
                    collection.Add(item);
                }
            }
            base.AddRange(collection);
            collection.Clear();
            return (A_0 == null);
        }

        public int c()
        {
            int num = 0;
            for (int i = 0; i < base.Count; i++)
            {
                num += base[i].g();
            }
            return num;
        }

        ~ContenitoreLivello()
        {
        }
    }
}

